#coding=utf-8
#Boa:FramePanel:PanelDate

import wx

[wxID_PANELDATE, wxID_PANELDATEBTNALLDATE, wxID_PANELDATEBTNONEDAY, 
 wxID_PANELDATEBTNONEMONTH, wxID_PANELDATEBTNONEWEEK, 
 wxID_PANELDATEBTNONEYEAR, wxID_PANELDATECHOICE, wxID_PANELDATEDATEEND, 
 wxID_PANELDATEDATESTART, wxID_PANELDATESTATICTEXT1, wxID_PANELDATETDATE, 
] = [wx.NewId() for _init_ctrls in range(11)]

class PanelDate(wx.Panel):
    def _init_ctrls(self, prnt):
        # generated method, don't edit
        wx.Panel.__init__(self, id=wxID_PANELDATE, name=u'PanelDate',
              parent=prnt, pos=wx.Point(268, 276), size=wx.Size(935, 115),
              style=wx.TAB_TRAVERSAL)
        self.SetClientSize(wx.Size(927, 81))
        self.SetFont(wx.Font(12, wx.SWISS, wx.NORMAL, wx.BOLD, False, u'Arial'))
        self.SetBackgroundColour(wx.Colour(183, 209, 173))

        self.TDate = wx.StaticText(id=wxID_PANELDATETDATE,
              label=u'\u67e5\u8be2\u65e5\u671f\uff1a', name=u'TDate',
              parent=self, pos=wx.Point(6, 14), size=wx.Size(85, 19), style=0)
        self.TDate.SetAutoLayout(True)
        self.TDate.SetFont(wx.Font(12, wx.SWISS, wx.NORMAL, wx.BOLD, False,
              u'Arial'))

        self.dateStart = wx.DatePickerCtrl(id=wxID_PANELDATEDATESTART,
              name=u'dateStart', parent=self, pos=wx.Point(94, 6),
              size=wx.Size(120, 27), style=wx.DP_DROPDOWN)
        self.dateStart.SetLabel(u'2014-04-24')
        self.dateStart.SetValue(wx.DateTimeFromDMY(24, 3, 2014, 0, 0, 0))
        self.dateStart.SetToolTipString(u'dateStart')

        self.staticText1 = wx.StaticText(id=wxID_PANELDATESTATICTEXT1,
              label=u'\u81f3', name='staticText1', parent=self,
              pos=wx.Point(222, 14), size=wx.Size(18, 18), style=0)

        self.dateEnd = wx.DatePickerCtrl(id=wxID_PANELDATEDATEEND,
              name=u'dateEnd', parent=self, pos=wx.Point(246, 6),
              size=wx.Size(116, 27), style=wx.DP_DROPDOWN)

        self.choice = wx.Choice(choices=[], id=wxID_PANELDATECHOICE,
              name=u'choice', parent=self, pos=wx.Point(632, 8),
              size=wx.Size(160, 27), style=0)
        self.choice.Bind(wx.EVT_CHOICE, self.OnChoiceChoice,
              id=wxID_PANELDATECHOICE)

        self.btnOneDay = wx.Button(id=wxID_PANELDATEBTNONEDAY,
              label=u'\u5f53\u65e5', name=u'btnOneDay', parent=self,
              pos=wx.Point(370, 6), size=wx.Size(46, 29), style=0)
        self.btnOneDay.Bind(wx.EVT_BUTTON, self.OnBtnOneDayButton,
              id=wxID_PANELDATEBTNONEDAY)

        self.btnOneWeek = wx.Button(id=wxID_PANELDATEBTNONEWEEK,
              label=u'\u4e00\u5468', name=u'btnOneWeek', parent=self,
              pos=wx.Point(418, 6), size=wx.Size(46, 29), style=0)
        self.btnOneWeek.Bind(wx.EVT_BUTTON, self.OnBtnOneWeekButton,
              id=wxID_PANELDATEBTNONEWEEK)

        self.btnOneMonth = wx.Button(id=wxID_PANELDATEBTNONEMONTH,
              label=u'\u4e00\u6708', name=u'btnOneMonth', parent=self,
              pos=wx.Point(466, 6), size=wx.Size(46, 29), style=0)
        self.btnOneMonth.Bind(wx.EVT_BUTTON, self.OnBtnOneMonthButton,
              id=wxID_PANELDATEBTNONEMONTH)

        self.btnOneYear = wx.Button(id=wxID_PANELDATEBTNONEYEAR,
              label=u'\u4e00\u5e74', name=u'btnOneYear', parent=self,
              pos=wx.Point(514, 6), size=wx.Size(46, 29), style=0)
        self.btnOneYear.Bind(wx.EVT_BUTTON, self.OnBtnOneYearButton,
              id=wxID_PANELDATEBTNONEYEAR)

        self.btnAllDate = wx.Button(id=wxID_PANELDATEBTNALLDATE,
              label=u'\u5168\u90e8', name=u'btnAllDate', parent=self,
              pos=wx.Point(562, 6), size=wx.Size(46, 29), style=0)
        self.btnAllDate.Bind(wx.EVT_BUTTON, self.OnBtnAllDateButton,
              id=wxID_PANELDATEBTNALLDATE)

    def __init__(self, parent):
        self._init_ctrls(parent)
        
        self._init_choice()
        self._init_data()
        
    def _init_data(self):
        self.dateStart.SetValue(wx.DateTime.Today())
        self.dateEnd.SetValue(wx.DateTime.Today())
        
    def _init_choice(self):
        self.today = self.choice.Append(u'今天')
        self.day7 = self.choice.Append(u'近7天内')
        self.day10 = self.choice.Append(u'近10天内')
        self.day30 = self.choice.Append(u'近30天内')
        self.curMonth = self.choice.Append(u'本月度')
        self.curYear = self.choice.Append(u'本年度')
        
        self.all = self.choice.Append(u'全部')

    def OnChoiceChoice(self, event):
        if (event.GetSelection() == self.today):
            self.dateStart.SetValue(wx.DateTime.Today())
            self.dateEnd.SetValue(wx.DateTime.Today())
            
        elif (event.GetSelection() == self.day7):
            day = wx.DateTime.Today()
            self.dateEnd.SetValue(day)
            
            span = wx.DateSpan.Days(7)
            day.SubtractDS(span)
            self.dateStart.SetValue(day)
            
        elif (event.GetSelection() == self.day10):
            pass
        
        elif (event.GetSelection() == self.day30):
            pass
        
        elif (event.GetSelection() == self.curMonth):
            pass
        
        elif (event.GetSelection() == self.curYear):
            pass
        
        elif (event.GetSelection() == self.all):
            pass

    def OnBtnOneDayButton(self, event):
        self.dateStart.SetValue(wx.DateTime.Today())
        self.dateEnd.SetValue(wx.DateTime.Today())

    def OnBtnOneWeekButton(self, event):
        day = wx.DateTime.Today()
        self.dateEnd.SetValue(day)
        
        span = wx.DateSpan.Days(7)
        day.SubtractDS(span)
        self.dateStart.SetValue(day)
        
    def OnBtnOneMonthButton(self, event):
        day = wx.DateTime.Today()
        self.dateEnd.SetValue(day)
        
        span = wx.DateSpan.Months(1)
        day.SubtractDS(span)
        self.dateStart.SetValue(day)

    def OnBtnOneYearButton(self, event):
        day = wx.DateTime.Today()
        self.dateEnd.SetValue(day)
        
        span = wx.DateSpan.Years(1)
        day.SubtractDS(span)
        self.dateStart.SetValue(day)

    def OnBtnAllDateButton(self, event):
        self.dateEnd.SetValue(wx.DateTime.Today())        
        self.dateStart.SetValue(wx.DateTimeFromDMY(1,0,2000,0,0,00))
        
    def getDateStart(self):
        self.dateStart.GetValue().Format('%Y-%m-%d')
        
    def getDateEnd(self):
        self.dateEnd.GetValue().Format('%Y-%m-%d')